package javbot.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

public class ConsolePanel extends JPanel {

	private static final long serialVersionUID = 2951376566864605030L;
	public static final int CONSOLE_WIDTH = 200;
	private JTextPane jtpConsole = null;
	private JScrollPane jScrollPane = null;
	
	
	/**
	 * This is the default constructor
	 */
	public ConsolePanel() {
		super();
		initialize();
		setPreferredSize(new Dimension(CONSOLE_WIDTH,0));	
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setLayout(new BorderLayout());
		this.setSize(300, 200);
		this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
	}

	/**
	 * This method initializes jtpConsole	
	 * 	
	 * @return javax.swing.JTextPane	
	 */
	private JTextPane getJtpConsole() {
		if (jtpConsole == null) {
			jtpConsole = new JTextPane();
			jtpConsole.setEditable(false);
			jtpConsole.setContentType("text/plain");
			jtpConsole.setBackground(new java.awt.Color(175,159,218));
		}
		return jtpConsole;
	}
	
	private void append(String line) {
		String newText = jtpConsole.getText() + line;
		jtpConsole.setText(newText);
		jtpConsole.setCaretPosition(newText.length());
	}
	
	public void output(String s) {
		System.out.println(s);	
		append(s);
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setViewportView(getJtpConsole());
		}
		return jScrollPane;
	}
}
